<?php

/**
 * 
 * Ezt a controllert minden admin controller osztálynak örökölnie kell
 * 
 * 
 * 1. bejelentkezés ellenőrzés
 * (todo : 2. jogosultság ellenőrzés az igényelt felülethez)
 * 3. teljes view betöltés függvény
 * 
 */
if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Admin_controller extends CI_Controller {
    
    public $data = NULL;
    
    function __construct() {
        parent::__construct();
        
        // CHECK LOGIN                     << START >>
        $this->data['userdata'] =
                (object) $this->session->userdata("ZenAuthSessionData");
        
        if(!isset($this->data['userdata']->user_logged_in)){
            redirect('admin/login');
            die();
        }
        
        $is_logged_in = $this->data['userdata']->user_logged_in;
        if (!isset($is_logged_in) || $is_logged_in != TRUE) {
            redirect('admin/login');
            die();
        }
        $this->benchmark->mark('admin_start');
        // CHECK LOGIN                      << END >>
        // ucms adatok betöltése config-ból (menü is)
        $this->load->config('ucms', TRUE);
        $ucms_data = $this->config->item('ucms');
        $this->data['menu'] = $ucms_data['menu'];
        // error message és message kiolvasás flashdata-bol
        $this->data['error_message'] = $this->session->flashdata('error_message');
        $this->data['message'] = $this->session->flashdata('message');
        //$this->load->helper('cookie');
        $this->load->helper('form');
        $this->load->library('form_validation');
    }

    /**
     * 
     * 
     * Teljes view betöltése
     * @param type $main 
     */
    function _load_view($main) {
        $this->load->view('admin/header_view', $this->data);
        $this->load->view('admin/sidebar_left_view', $this->data);
        $this->load->view($main, $this->data);
        $this->benchmark->mark('admin_end');
        $this->data['footer_benchmark'] = $this->benchmark->elapsed_time('admin_start', 'admin_end');
        $this->load->view('admin/footer_view', $this->data);
    }

}